<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<text class="title">10086</text>
			<button type="primary" @click="clickPhone">拨打电话</button>
		</view>
		<view>国际化</view>
		<button type="primary" @click="handleChangeLanguage">修改语言</button>
		<view class="title">{{$t('home.title')}}</view>
		<view>paypal支付</view>
		<button type="primary" @click="handlePaypal">paypal支付</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '你好',
				index: 1,
				lang: 'zh-Hans',
				clientId: "ATGjtjTpMF8QAyZRWKoLzD8qTPdWGlMBk4r950mgh0R6wHi7ss4K4EwBwra38gTQB0pVgu1soz4uuEE8", //开发者中心clientId
				orderId: '5LU333387W408242W', //订单id
			}
		},
		onLoad() {
			console.log('this.$i18n.locale:', this.$i18n.locale)
			console.log('uni.getLocale():', uni.getLocale())

		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.$t('home.title')
			})
		},
		methods: {
			// 唤起打电话
			clickPhone() {
				uni.makePhoneCall({
					// phoneNumber: '17749589824'
					phoneNumber: '10086'
				});
				this.index = this.index + 1
			},
			// 国际化
			handleChangeLanguage() {
				this.lang = uni.getStorageSync('lang') || 'zh-Hans'
				console.log('修改前this.lang:', this.lang)
				if (this.lang === 'zh-Hans') {
					this.lang = 'en'
				} else {
					this.lang = 'zh-Hans'
				}
				this.$i18n.locale = this.lang
				uni.setStorageSync('lang', this.lang)
				uni.setLocale(this.lang)
				uni.setNavigationBarTitle({
					title: this.$t('home.title')
				})
				uni.setTabBarItem({
					index: 0,
					text: this.$t('home.title'),
				})
				uni.setTabBarItem({
					index: 1,
					text: this.$t('message.title'),
				})
				uni.setTabBarItem({
					index: 2,
					text: this.$t('my.title'),
				})
			},
			handlePaypal() {
				// #ifdef APP-PLUS || H5
				let orderInfo = {
					"clientId": this.clientId, //开发者中心clientId
					"orderId": this.orderId, //订单id
					"userAction": "continue", //按钮样式 paynow/continue
					"currency": "USD", //币种
					"environment": "sandbox" //运行环境 sandbox(沙盒) / live(线上)
				};
				console.log('orderInfo:', orderInfo)
				uni.requestPayment({
					"provider": "paypal",
					"orderInfo": orderInfo,
					success: function(response) {
						console.log('success:' + JSON.parse(response.rawdata));
					},
					fail: function(err) {
						console.log('fail:' + JSON.stringify(err));
					}
				});
				// #endif
			},
			
			
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>